//
//  Btn.m
//

#import "Btn.h"

@implementation BtnThumb

-(id) init
{
	return [self initWithTarget:nil selector:nil];
}

-(id) initWithTarget:(id)t selector:(SEL)sel
{
	[super initFromNormalImage:@"button.png" selectedImage:@"button_on.png" disabledImage:nil target:t selector:sel];
	return self;
}

-(int) Id
{
	return Id_;
}
-(void) setId:(int)_Id
{
	Id_ = _Id;
}

@end


@interface BtnTouchLogic : CCMenu
{
	BtnThumb* _thumb;
	BOOL _liveDragging;
}

@property (readonly) BtnThumb* thumb;

-(id) initWithTarget:(id)t selector:(SEL)sel;

@end


@implementation BtnTouchLogic


-(id) init
{
	return [self initWithTarget:nil selector:nil];
}

-(id) initWithTarget:(id)t selector:(SEL)sel
{
	[super initWithItems:nil vaList:nil];
	self.position = ccp(0,0);
	
	_liveDragging = NO;
	_thumb = [[[BtnThumb alloc] initWithTarget:t selector:sel] autorelease];
	[self addChild:_thumb];
	
	return self;
}

-(BtnThumb*) thumb
{
	return _thumb;
}

-(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
	if ([super ccTouchBegan:touch withEvent:event])
	{
		[self ccTouchMoved:touch withEvent:event];
		return YES;
	}
	else
		return NO;
}

-(void) ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event
{
	[super ccTouchEnded:touch withEvent:event];
}

@end



@implementation Btn

-(id) init
{
	return [self initWithTarget:nil selector:nil];
}

-(id) initWithTarget:(id)t selector:(SEL)sel
{
	[super init];
	
	_touchLogic = [[[BtnTouchLogic alloc] initWithTarget:t selector:sel] autorelease];
	[self addChild:_touchLogic];
	
	return self;
}

-(BtnThumb*) thumb
{
	return _touchLogic.thumb;
}

-(int) Id
{
	return self.thumb.Id;
}
-(void) setId:(int)_Id
{
	[self.thumb setId:_Id];
}

@end
